#!/usr/bin/env python 
#+_+ coding:utf-8 +_+

import commands
import sys

def execmd(cmd):
    force = False
    if cmd[0]=='-':
        cmd  = cmd[1:]
        force = True
    status,output = commands.getstatusoutput(cmd)
    if not force and not status :
        print "[FAILED]while do cmd :{cmd}".format(cmd=cmd)
        sys.exit(-1)
    print "[DONE] cmd :{cmd}".format(cmd=cmd)

def cpbin():
    cmd = "mkdir dist/bin && cp -fr  src/* dist/bin "
    execmd(cmd)

def cpcfg():
    cmd = "mkdir dist/conf.d && cp -fr config/* dist"
    execmd(cmd)

def cpsvn():
    cmd = "-rm /home/gota/Repos/sae.sina.com.cn/tornado4wx/1/dist -rf"
    execmd(cmd)
    cmd = "cp dist /home/gota/Repos/sae.sina.com.cn/tornado4wx/1 -rf"
    execmd(cmd)
     
def main():
    print "Start building..."
    print "copy bin.."
    cpbin()

    print "copy config files ..."
    cpcfg()

    print "copy to sae..."
    cpsvn()

    print "End building"


if __name__ == "__main__":
    main()
